package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.entity.HonorsWon;
import com.wanmait.wanmarecruit.service.JobOrientationService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.mapper.JobOrientationMapper;
import com.wanmait.wanmarecruit.entity.JobOrientation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class JobOrientationServiceImpl extends ServiceImpl<JobOrientationMapper, JobOrientation> implements JobOrientationService {

    @Resource
    private JobOrientationMapper jobOrientationMapper;
    @Override
    public List<JobOrientation> getJobOrientationByUserId(Integer userId) {
        return jobOrientationMapper.selectJobOriByUserId(userId);
    }

    @Override
    public void saveJobOrientationByUser(List<JobOrientation> jobOrientationList, Integer userId) {
        if (userId!=null) {
            LambdaQueryWrapper<JobOrientation> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(JobOrientation::getUserId,userId);
            this.remove(queryWrapper);
            for (int i = 0; i < jobOrientationList.size(); i++) {
                jobOrientationList.get(i).setUserId(userId);
            }
            this.saveBatch(jobOrientationList);
        }
    }
}
